home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / pupi-button.scm < prev    next >
Encoding:
Text File  |  2009-08-19  |  7.5 KB  |  212 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Round Button --- create a round beveled Web button.
  5. ; Copyright (C) 1998 Federico Mena Quintero & Arturo Espinosa Aldama
  6. ; federico@nuclecu.unam.mx arturo@nuclecu.unam.mx
  7. ; ************************************************************************
  8. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  9. ; For use with GIMP 1.1.
  10. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  11. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  12. ; ************************************************************************
  13. ;
  14. ; This program is free software: you can redistribute it and/or modify
  15. ; it under the terms of the GNU General Public License as published by
  16. ; the Free Software Foundation; either version 3 of the License, or
  17. ; (at your option) any later version.
  18. ;
  19. ; This program is distributed in the hope that it will be useful,
  20. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ; GNU General Public License for more details.
  23. ;
  24. ; You should have received a copy of the GNU General Public License
  25. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  26.  
  27. (define (script-fu-round-button text
  28.                                 size
  29.                                 font
  30.                                 ul-color
  31.                                 lr-color
  32.                                 text-color
  33.                                 ul-color-high
  34.                                 lr-color-high
  35.                                 hlight-color
  36.                                 xpadding
  37.                                 ypadding
  38.                                 bevel
  39.                                 ratio
  40.                                 notpressed
  41.                                 notpressed-active
  42.                                 pressed)
  43.  
  44.   (cond ((eqv? notpressed TRUE)
  45.          (do-pupibutton text size font ul-color lr-color
  46.                         text-color xpadding ypadding bevel ratio 0)))
  47.   (cond ((eqv? notpressed-active TRUE)
  48.          (do-pupibutton text size font ul-color-high lr-color-high
  49.                         hlight-color xpadding ypadding bevel ratio 0)))
  50.   (cond ((eqv? pressed TRUE)
  51.          (do-pupibutton text size font ul-color-high lr-color-high
  52.                         hlight-color xpadding ypadding bevel ratio 1))))
  53.  
  54. (define (do-pupibutton text
  55.                        size
  56.                        font
  57.                        ul-color
  58.                        lr-color
  59.                        text-color
  60.                        xpadding
  61.                        ypadding
  62.                        bevel
  63.                        ratio
  64.                        pressed)
  65.  
  66.   (define (text-width extents)
  67.     (car extents))
  68.  
  69.   (define (text-height extents)
  70.     (cadr extents))
  71.  
  72.   (define (text-ascent extents)
  73.     (caddr extents))
  74.  
  75.   (define (text-descent extents)
  76.     (cadr (cddr extents)))
  77.  
  78.   (define (round-select img
  79.                         x
  80.                         y
  81.                         width
  82.                         height
  83.                         ratio)
  84.     (let* ((diameter (* ratio height)))
  85.       (gimp-ellipse-select img x y diameter height CHANNEL-OP-ADD FALSE 0 0)
  86.       (gimp-ellipse-select img (+ x (- width diameter)) y
  87.                            diameter height CHANNEL-OP-ADD FALSE 0 0)
  88.       (gimp-rect-select img (+ x (/ diameter 2)) y
  89.                         (- width diameter) height CHANNEL-OP-ADD FALSE 0)))
  90.  
  91.   (let* (
  92.         (text-extents (gimp-text-get-extents-fontname text
  93.                                                       size
  94.                                                       PIXELS
  95.                                                       font))
  96.         (ascent (text-ascent text-extents))
  97.         (descent (text-descent text-extents))
  98.  
  99.         (height (+ (* 2 (+ ypadding bevel))
  100.                        (+ ascent descent)))
  101.  
  102.         (radius (/ (* ratio height) 4))
  103.  
  104.         (width (+ (* 2 (+ radius xpadding))
  105.                   bevel
  106.                   (text-width text-extents)))
  107.  
  108.         (img (car (gimp-image-new width height RGB)))
  109.  
  110.         (bumpmap (car (gimp-layer-new img width height
  111.                                       RGBA-IMAGE "Bumpmap" 100 NORMAL-MODE)))
  112.         (gradient (car (gimp-layer-new img width height
  113.                                        RGBA-IMAGE "Button" 100 NORMAL-MODE)))
  114.         )
  115.  
  116.     (gimp-context-push)
  117.  
  118.     (gimp-image-undo-disable img)
  119.  
  120.     ; Create bumpmap layer
  121.  
  122.     (gimp-image-add-layer img bumpmap -1)
  123.     (gimp-selection-none img)
  124.     (gimp-context-set-background '(0 0 0))
  125.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  126.  
  127.     (round-select img (/ bevel 2) (/ bevel 2)
  128.                   (- width bevel) (- height bevel) ratio)
  129.     (gimp-context-set-background '(255 255 255))
  130.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  131.  
  132.     (gimp-selection-none img)
  133.     (plug-in-gauss-rle RUN-NONINTERACTIVE img bumpmap bevel 1 1)
  134.  
  135.     ; Create gradient layer
  136.  
  137.     (gimp-image-add-layer img gradient -1)
  138.     (gimp-edit-clear gradient)
  139.     (round-select img 0 0 width height ratio)
  140.     (gimp-context-set-foreground ul-color)
  141.     (gimp-context-set-background lr-color)
  142.  
  143.     (gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
  144.                      GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  145.                      FALSE 0 0 TRUE
  146.                      0 0 0 (- height 1))
  147.  
  148.     (gimp-selection-none img)
  149.  
  150.     (plug-in-bump-map RUN-NONINTERACTIVE img gradient bumpmap
  151.                       135 45 bevel 0 0 0 0 TRUE pressed 0)
  152.  
  153. ;     Create text layer
  154.  
  155.     (cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
  156.  
  157.     (gimp-context-set-foreground text-color)
  158.     (let ((textl (car (gimp-text-fontname
  159.                        img -1 0 0 text 0 TRUE size PIXELS
  160.                        font))))
  161.       (gimp-layer-set-offsets textl
  162.                               (+ xpadding radius bevel)
  163.                               (+ ypadding descent bevel)))
  164.  
  165. ;   Delete some fucked-up pixels.
  166.  
  167.     (gimp-selection-none img)
  168.     (round-select img 1 1 (- width 1) (- height 1) ratio)
  169.     (gimp-selection-invert img)
  170.     (gimp-edit-clear gradient)
  171.  
  172. ;     Done
  173.  
  174.     (gimp-image-remove-layer img bumpmap)
  175.     (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
  176.  
  177.     (gimp-selection-none img)
  178.     (gimp-image-undo-enable img)
  179.     (gimp-display-new img)
  180.  
  181.     (gimp-context-pop)
  182.   )
  183. )
  184.  
  185. (script-fu-register "script-fu-round-button"
  186.   _"_Round Button..."
  187.   _"Create images, each containing an oval button graphic"
  188.   "Arturo Espinosa (stolen from quartic's beveled button)"
  189.   "Arturo Espinosa & Federico Mena Quintero"
  190.   "June 1998"
  191.   ""
  192.   SF-STRING     _"Text"                 "GIMP"
  193.   SF-ADJUSTMENT _"Font size (pixels)"   '(16 2 100 1 1 0 1)
  194.   SF-FONT       _"Font"                 "Sans"
  195.   SF-COLOR      _"Upper color"          '(192 192 0)
  196.   SF-COLOR      _"Lower color"          '(128 108 0)
  197.   SF-COLOR      _"Text color"           "black"
  198.   SF-COLOR      _"Upper color (active)" '(255 255 0)
  199.   SF-COLOR      _"Lower color (active)" '(128 108 0)
  200.   SF-COLOR      _"Text color (active)"  '(0 0 192)
  201.   SF-ADJUSTMENT _"Padding X"            '(4 0 100 1 10 0 1)
  202.   SF-ADJUSTMENT _"Padding Y"            '(4 0 100 1 10 0 1)
  203.   SF-ADJUSTMENT _"Bevel width"          '(2 0 100 1 10 0 1)
  204.   SF-ADJUSTMENT _"Round ratio"          '(1 0.05 20 0.05 1 2 1)
  205.   SF-TOGGLE     _"Not pressed"          TRUE
  206.   SF-TOGGLE     _"Not pressed (active)" TRUE
  207.   SF-TOGGLE     _"Pressed"              TRUE
  208. )
  209.  
  210. (script-fu-menu-register "script-fu-round-button"
  211.                          "<Image>/File/Create/Buttons")
  212.